import { queryCategoryList } from "@/api/category.api";
import { Category, CategoryList } from "@/types/category";
import { onMounted, reactive } from "vue";
interface CategoryData {
  list: CategoryList;
  current: Category | null;
}
export const useCategory = (): {
  categoryList: CategoryData;
} => {
  const categoryList = reactive<CategoryData>({
    list: [],
    current: null,
  });
  const getCateGoryList = async () => {
    const res = await queryCategoryList();
    if (res.code === 200) {
      categoryList.list = res.data || [];
    }
  };
  onMounted(() => {
    getCateGoryList();
  });
  return {
    categoryList,
  };
};
